package com.hbnu.servlet;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author kittychen
 * @since 2025-11-03 14:30
 */
public class MyServletDemo01 implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        System.out.println("创建Servlet实例对象时进行初始化，创建Servlet实例对象的时候调用");
        // 获取初始化参数
        String username = servletConfig.getInitParameter("username");
        String email = servletConfig.getInitParameter("email");
        System.out.println("username = " + username);
        ServletContext servletContext = servletConfig.getServletContext();
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        // 给浏览器返回一个简短的消息
        servletResponse.getWriter().write("Hello Servlet");
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("销毁Servlet实例对象时进行销毁，销毁Servlet实例对象的时候调用");
    }
}
